﻿<UserControl x:Class="ScrumFactory.Backlog.BacklogItemDetail"
             x:Name="thisView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             
             xmlns:props="clr-namespace:ScrumFactory.Backlog.Properties"
             
         
             
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.InputBindings>        
        <KeyBinding Key="PageDown" Command="{Binding NavigateToNextItemCommand}" />
        <KeyBinding Key="PageUp" Command="{Binding NavigateToNextItemCommand}" />
    </UserControl.InputBindings>
    
    <UserControl.Resources>                
        <DataTemplate x:Key="SizeDropDownDataTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>                
                <StackPanel Grid.Column="0" Orientation="Vertical">
                    <TextBlock Text="{Binding ItemSize.Name}" TextWrapping="Wrap"/>
                    <TextBlock
                            Width="200" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxHeight="60"
                            HorizontalAlignment="Left"
                            FontSize="{StaticResource SmallFontSize}" Foreground="{StaticResource SubTextBrush}"
                            Text="{Binding ItemSize.Description}"/>
                </StackPanel>
                <TextBlock
                            Grid.Column="1"
                            VerticalAlignment="Center"   Margin="5,0,0,0"
                            FontSize="{StaticResource ReallyBigFontSize}" Foreground="{StaticResource LabelBrush}" FontWeight="Bold"
                            Text="{Binding ItemSize.Size}"/>

            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="IssueDataTemplate">
            <StackPanel Orientation="Horizontal">
                <Image DataContext="{Binding}" Style="{StaticResource IssueImage}" Width="20" Height="20" Stretch="Uniform" />
                <TextBlock Margin="5,0,0,0" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </StackPanel>
        </DataTemplate>
        
    </UserControl.Resources>

    <TabControl Style="{StaticResource WindowTabControl}">
        <TabControl.Items>
             <TabItem Header="{Binding PanelName}" IsSelected="{Binding IsFirstTabSelected}">
                    <SF_Helpers:PanelLayout Title="{Binding PanelName}">

                        <!-- TOOLBAR -->
                        <SF_Helpers:PanelLayout.Toolbar>
                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <ToolBar Grid.Column="0">
                                    <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                                    <Border>
                                        <StackPanel Orientation="Horizontal">
                                            <MenuItem Header="{x:Static props:Resources.Previous_item}"
                                              ToolTip="{x:Static props:Resources.Previous_item_tooltip}"
                                              Command="{Binding NavigateToPreviousItemCommand}">
                                                <MenuItem.Icon>
                                                    <Image Source="/Images/ToolBar/upArrow.png" Width="32" Height="32" Stretch="Uniform"/>
                                                </MenuItem.Icon>
                                            </MenuItem>
                                            <MenuItem
                                            Header="{x:Static props:Resources.Next_item}"
                                            ToolTip="{x:Static props:Resources.Next_item_tooltip}"
                                            Command="{Binding NavigateToNextItemCommand}">
                                                <MenuItem.Icon>
                                                    <Image Source="/Images/ToolBar/downArrow.png" Width="32" Height="32" Stretch="Uniform"/>
                                                </MenuItem.Icon>
                                            </MenuItem>
                                        </StackPanel>
                                    </Border>

                                    <MenuItem Header="{x:Static props:Resources.Plan_items}" Command="{Binding MoveItemToCurrentSprintCommand}"
                                        Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                                        <MenuItem.Icon>
                                            <Image Source="/Images/ToolBar/planItems.png" Width="32" Height="32" Stretch="Uniform"/>
                                        </MenuItem.Icon>
                                    </MenuItem>

                                </ToolBar>

                                <ToolBar Grid.Column="1">
                                    <Border>
                                        <StackPanel VerticalAlignment="Center" Margin="5,0,5,0">
                                            <TextBlock Text="{Binding ItemSizeString}" FontFamily="{StaticResource WideFont}" FontSize="{StaticResource ReallyBigFontSize}" Foreground="{StaticResource LabelBrush}" HorizontalAlignment="Center"/>
                                            <TextBlock FontSize="{StaticResource SmallFontSize}" Foreground="{StaticResource LabelBrush}" Margin="5,0,0,0" Text="{x:Static props:Resources.pts}" HorizontalAlignment="Center"/>
                                        </StackPanel>
                                    </Border>
                                </ToolBar>

                            </Grid>
                        </SF_Helpers:PanelLayout.Toolbar>

                        <!-- CONTENT -->
                        <SF_Helpers:PanelLayout.Content>

                            <Grid VerticalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition x:Name="dataColumn" Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <TextBlock                                       
                        Grid.Column="0" Grid.Row="0"
                        Text="{x:Static props:Resources.Item}"
                        Style="{StaticResource LabelTextBlock}"/>
                            <Grid Grid.Column="1"  Grid.Row="0" HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBox                                                                                         
                                    Grid.Column="0"
                                    x:Name="itemName"
                                        IsReadOnly="{Binding UserCannotEdit}"
                                    HorizontalAlignment="Stretch"                        
                                    Text="{Binding Item.Name, UpdateSourceTrigger=PropertyChanged}"/>

                                <ComboBox         
                                    Grid.Column="1"
                                
                                IsReadOnly="{Binding UserCannotEdit}"
                                ItemTemplate="{StaticResource IssueDataTemplate}"
                                SelectedValue="{Binding Item.IssueType, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:IssueTypes}, UpdateSourceTrigger=PropertyChanged}"                                                        
                                ItemsSource="{Binding Source={StaticResource BacklogItemIssueList}}"/>
                            </Grid>

                            
                                <TextBlock
                                    Grid.Column="0" Grid.Row="1"                            
                                    Text="{x:Static props:Resources.Size}"
                                    Style="{StaticResource LabelTextBlock}"/>

                            <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
                                <SF_Helpers:FilteredComboBox                                    
                                    HorizontalAlignment="Left" Width="500" 
                                    ContainsFilter="True" MaxItemsResults="8" MaxDropDownHeight="600"  
                                    AlternationCount="2"                        
                                    SelectedItem="{Binding ItemSize, UpdateSourceTrigger=PropertyChanged}" 
                                    IsEditable="True" IsReadOnly="{Binding UserCannotEdit}"
                                    ItemTemplate="{StaticResource SizeDropDownDataTemplate}"
                                    ItemsSource="{Binding Sizes}"/>
                                <!--<ComboBox                                    
                                    HorizontalAlignment="Left" Width="500" 
                                    IsTextSearchEnabled="True"
                                    AlternationCount="2"                        
                                    SelectedItem="{Binding ItemSize, UpdateSourceTrigger=PropertyChanged}" 
                                    IsEditable="True" IsReadOnly="{Binding UserCannotEdit}"
                                    ItemTemplate="{StaticResource SizeDropDownDataTemplate}"
                                    ItemsSource="{Binding Sizes}"/>-->
                                <TextBlock                                     
                                    Text="{x:Static props:Resources.x_size_factor}" Style="{StaticResource LabelTextBlock}"/>
                                <TextBox
                                    SF_Ext:TextBoxExtension.AutoSelectOnFocus="True"
                                    SF_Ext:TextBoxExtension.NumericJumper="1"
                                    Text="{Binding SizeFactor, UpdateSourceTrigger=LostFocus}" Width="50" TextAlignment="Right"/>
                            </StackPanel>
                            

                            <!--<ComboBox
                                    Grid.Column="1" Grid.Row="1"
                                    HorizontalAlignment="Left" Width="500" 
                                    MaxDropDownHeight="600"  
                                    AlternationCount="2"                        
                                    SelectedItem="{Binding ItemSize, UpdateSourceTrigger=PropertyChanged}" 
                                    IsEditable="True" IsReadOnly="{Binding UserCannotEdit}"
                                    ItemTemplate="{StaticResource SizeDropDownDataTemplate}"
                                    ItemsSource="{Binding Sizes}"/>-->



                            <TextBlock                                              
                        Grid.Column="0" Grid.Row="2"                        
                        VerticalAlignment="Top"
                        TextWrapping="Wrap"
                        Style="{StaticResource LabelTextBlock}" Margin="0">
                        <TextBlock                                                  
                            Text="{Binding Item.SprintNumber, StringFormat={x:Static props:Resources.Hours_to_finish}}"
                            VerticalAlignment="Top" TextWrapping="Wrap"
                            Style="{StaticResource LabelTextBlock}"/>
                        <LineBreak/>
                        <TextBlock             
                            Foreground="{StaticResource SubTextBrush}"                            
                            FontSize="{StaticResource TinyFontSize}"
                            TextWrapping="Wrap"
                            Text="{Binding Item.PlanningNumber, StringFormat={x:Static props:Resources.last_planned_at}}">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource LabelTextBlock}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Item.PlanningNumber}" Value="0">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                            </TextBlock>
                    </TextBlock>

                            <Grid Grid.Column="1" Grid.Row="2" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="auto"/>
                                </Grid.ColumnDefinitions>
                                
                                <ItemsControl
                                        Grid.Column="0"
                                        IsTabStop="False"
                                        ItemsSource="{Binding PlannedHours}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Vertical" Width="60" >
                                                <TextBox
                                                        SF_Ext:TextBoxExtension.AutoSelectOnFocus="True"
                                                        IsReadOnly="{Binding ElementName=thisView, Path=Model.UserCannotEditHours}"                                        
                                                        FontSize="{StaticResource ReallyBigFontSize}"
                                                        HorizontalContentAlignment="Right"
                                                        HorizontalAlignment="Stretch"
                                                        Text="{Binding Hours, StringFormat='{}0.#', UpdateSourceTrigger=PropertyChanged}"
                                                        FontWeight="Bold">
                                                    <TextBox.Style>
                                                        <Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="TextBox">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Role.PermissionSet}" Value="2">
                                                                    <Setter Property="TextBox.Background" Value="Azure"/>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding Role.PermissionSet}" Value="3">
                                                                    <Setter Property="TextBox.Background" Value="Azure"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </TextBox.Style>
                                                </TextBox>
                                                <TextBlock
                                                        Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}"
                                                        Text="{Binding Role.RoleName}"
                                                        TextWrapping="Wrap"
                                                        HorizontalAlignment="Center"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>

                                <ItemsControl  
                                        Grid.Column="0"
                                        IsTabStop="False"
                                        ItemsSource="{Binding SuggestedHours}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Width="24" Height="24" Margin="0,-5,36,0" VerticalAlignment="Top" HorizontalAlignment="Right">
                                                <Ellipse Fill="{StaticResource AlertBrush}"/>
                                                <Viewbox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3">
                                                    <TextBlock                                                                                   
                                                HorizontalAlignment="Center" VerticalAlignment="Center"
                                                Foreground="Yellow"
                                                FontSize="{StaticResource SmallFontSize}"
                                                Text="{Binding Hours, StringFormat='{}0.#'}"/>
                                                </Viewbox>
                                            </Grid>

                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>

                                <TextBlock Grid.Column="1"
                                           Foreground="{StaticResource AlertBrush}" 
                                           FontSize="{StaticResource SmallFontSize}"
                                           TextWrapping="Wrap" Width="200"
                                           Text="{x:Static props:Resources.Suggested_hours_tooltip}" Margin="10,0,0,0">
                                    <TextBlock.Style>
                                        <Style>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding SuggestedHours}" Value="{x:Null}">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>

                            </Grid>
                                
                         
                            


                            <TextBlock                          
                            Grid.Column="0" Grid.Row="3"
                            Text="{x:Static props:Resources.Status}"                        
                            Style="{StaticResource LabelTextBlock}"/>
                                <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
                                    <ComboBox                                                    
                                HorizontalAlignment="Left"           
                                IsReadOnly="{Binding UserCannotEdit}"
                                ItemTemplate="{StaticResource StatusItemDataTemplate}"
                                SelectedValue="{Binding ItemStatus, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:BacklogItemStatus}, UpdateSourceTrigger=PropertyChanged}"                        
                                Width="220"
                                ItemsSource="{Binding Source={StaticResource BacklogItemStatusList}}"/>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{x:Static props:Resources.started_at}" Style="{StaticResource LabelTextBlock}"/>
                                        <DatePicker SelectedDate="{Binding Item.StartedAt, UpdateSourceTrigger=PropertyChanged}"/>
                                        <TextBlock Text="{x:Static props:Resources.finished_at}" Style="{StaticResource LabelTextBlock}"/>
                                        <DatePicker SelectedDate="{Binding Item.FinishedAt, UpdateSourceTrigger=PropertyChanged}" />
                                        <StackPanel.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Item.Status}" Value="0">
                                                        <Setter Property="StackPanel.Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </StackPanel.Style>
                                    </StackPanel>
                                </StackPanel>

                                <TextBlock Grid.Column="0"  Grid.Row="4"
                               Text="{x:Static props:Resources.Description}"                               
                               Style="{StaticResource LabelTextBlock}" VerticalAlignment="Top"/>
                                <TextBox Grid.Column="1"  Grid.Row="4"
                             Text="{Binding Item.Description, UpdateSourceTrigger=PropertyChanged}"                             
                             AcceptsReturn="True" TextWrapping="Wrap" 
                             IsReadOnly="{Binding UserCannotEdit}" 
                             HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                                

                            </Grid>

                        </SF_Helpers:PanelLayout.Content>

                    </SF_Helpers:PanelLayout>
            </TabItem>
            <TabItem Header="{x:Static props:Resources.Schedule}">
                <SF_Helpers:PanelLayout Title="{x:Static props:Resources.Schedule}">
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar Grid.Column="0">
                            <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                        </ToolBar>                    
                    </SF_Helpers:PanelLayout.Toolbar>
                    <SF_Helpers:PanelLayout.Content>
                        <StackPanel Orientation="Vertical">
                            <RadioButton Content="{x:Static props:Resources.Delivery_at_the_end_of_the_sprint}" GroupName="delivery">
                                <RadioButton.Style>
                                    <Style TargetType="{x:Type RadioButton}" BasedOn="{StaticResource {x:Type RadioButton}}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding HasDeliveryDate}" Value="False">
                                                <Setter Property="IsChecked" Value="True"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding HasDeliveryDate}" Value="True">
                                                <Setter Property="IsChecked" Value="False"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </RadioButton.Style>
                            </RadioButton>
                            <RadioButton Content="{x:Static props:Resources.Delivery_at}" x:Name="deliveryAtRadio" GroupName="delivery" IsChecked="{Binding HasDeliveryDate}"/>                                
                            <Viewbox Width="250" Height="250">
                                <Calendar
                                    FocusManager.IsFocusScope="False"
                                    SelectedDate="{Binding DeliveryDate}"
                                    DisplayDateStart="{Binding Sprint.StartDate, Mode=OneTime}"
                                    DisplayDateEnd="{Binding Sprint.EndDate, Mode=OneTime}">
                                    <Calendar.Style>
                                        <Style BasedOn="{StaticResource {x:Type Calendar}}" TargetType="{x:Type Calendar}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding ElementName=deliveryAtRadio, Path=IsChecked}" Value="False">
                                                    <Setter Property="Calendar.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Calendar.Style>
                                </Calendar>
                            </Viewbox>
                            
                        </StackPanel>
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>
            </TabItem>
        </TabControl.Items>

    </TabControl>

        
        
    

    


</UserControl>
